package autoteam.ui.dialogs;

import java.awt.*;

import javax.swing.*;

import db.*;
import autoteam.tables.AutoTeamTableModel;

public class SearchLeagueDialog extends AutoTeamDialog
{
	private static final long serialVersionUID = 1L;

	private DataAccessObject dao;
	
	private JLabel league;
	private final JLabel sportLabel = new JLabel("Sport:");	
	private JLabel sport;
	
	public SearchLeagueDialog(JFrame dialogOwner, AutoTeamTableModel model, int row)
	{
		super();
		
		dao = new DataAccessObject();
		
		String temp = (String) model.getValueAt(row, 0);
		league = new JLabel(temp);
		
		ColumnData col = new ColumnData("leaguename", temp);
		DBRecord record = dao.getRecord("leagues", col);
		if (record.getFieldValue("sport") != null)
			sport = new JLabel(record.getFieldValue("sport").toString());
		else
			sport = new JLabel("not found");
		
		// set dialog preferences
		int dialogWidth = 250;
		int dialogHeight = 150;
		this.setDialogSize(new Dimension(dialogWidth, dialogHeight));
		Toolkit sizer = Toolkit.getDefaultToolkit();
		Dimension screenSize = sizer.getScreenSize();
		int screenCenterX = (screenSize.width - dialogWidth) / 2;
		int screenCenterY = (screenSize.height - dialogHeight) / 2;
		this.setLocation(screenCenterX, screenCenterY);
		
		// set layout preferences
		setLayout(null);
		int x = 50;		// x coordinate
		int y = 30;		// y coordinate
		int xGap = 50;	// gap between columns
		int yGap = 40;	// gap between rows
		
		int x1 = 50;	// column one width
		int x2 = 100;	// column two width
		int y1 = 20;	// row height
		
		int i = 0;
		league.setBounds(x, y, x1 + x2, y1);
		league.setHorizontalAlignment(JLabel.CENTER);
		i++;
		sportLabel.setBounds(x, y + (yGap * i), x1, y1);
		sport.setBounds(x + xGap, y + (yGap * i++), x2, y1);
		
		// add components
		add(league);
		add(sportLabel);
		add(sport);
	}

	@Override
	protected void setButtonActions(AutoTeamDialog thisDialog) {
		// TODO Auto-generated method stub
		
	}

}
